package com.atguigu.jdbc;

import java.sql.*;

/**
 * @author lhr
 */
public class SelectBooks {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1.加载类驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.连接数据库
        String url = "jdbc:mysql://localhost:3306/day04_test01_bookstore";
        Connection conn = DriverManager.getConnection(url, "root", "123456");

        //3.操作数据库
        String sql = "select * from books order by sales desc limit 0,1";
        PreparedStatement pst = conn.prepareStatement(sql);

        ResultSet rs = pst.executeQuery();
        while (rs.next()){
            for (int i = 1 ; i<=7 ; i++){
                System.out.print(rs.getObject(i)+"\t");
            }
            System.out.println();
        }
        rs.close();
        pst.close();
        conn.close();
    }
}
